package com.hospital.hospital.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hospital.hospital.bean.Department;
import com.hospital.hospital.bean.Doctor;
import com.hospital.hospital.mapper.DoctorMapper;
import com.hospital.hospital.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;


    @Override
    public List<Doctor> queryAll() throws Exception {
        List<Doctor> doctors = null;
        doctors = doctorMapper.queryAll();
        return doctors;
    }

    @Override
    public void deleteByDoctorId(Integer doctorId) throws Exception {
        doctorMapper.deleteByDoctorId(doctorId);
    }

    @Override
    public void insert(Doctor doctor) throws Exception {
        doctorMapper.insert(doctor);

    }

    @Override
    public void updateById(Doctor doctor) throws Exception {
        doctorMapper.updateById(doctor);
    }

    @Override
    public List<Doctor> queryLike(String likename) throws Exception {

        List<Doctor> doctors = doctorMapper.queryLike(likename);
        return doctors;
    }

    @Override
    public Doctor queryById(Integer doctorId) throws Exception {
        Doctor doctor = doctorMapper.queryById(doctorId);
        return doctor;
    }

    @Override
    public void testPage() throws Exception {
        PageHelper.startPage(2, 3);
        List<Doctor> doctors = doctorMapper.queryAll();
        PageInfo<Doctor> pageInfo = new PageInfo<>(doctors);

        System.out.println(pageInfo);

        System.out.println(pageInfo.getPageNum());
        System.out.println(pageInfo.getPageSize());
        List<Doctor> pageDoctors = pageInfo.getList();
        pageDoctors.forEach(doctor -> System.out.println(doctor));
    }

    @Override
    public List<Doctor> queryByPage(Integer page) {
        Integer p = (page -1)*4;
        List<Doctor> doctors = doctorMapper.queryByPage(p);
        return doctors;
    }


}